How to include a user-specific file

I have a DXL attribute that needs to include a file whose directory name is user specific, so the filename is variable. The user-specific file that is included sets some variables that are to be used in the DXL attribute's dxl code. I tried building a string with the include command and running eval_, but the settings of the DXL variables in the included file are not carrying back to the including file. I was thinking that eval_ executed inline so that the settings would be in scope, but it looks like that isn't what it is doing. Following is what I have been using to try this out.
 

string curUser = doorsname
string userFile = "C:/Users/" curUser "/settings.dxl"
string DXLVER = "init"
 
if (fileExists_(userFile))
{
    string inclLine = "#include \"" userFile "\""
    eval_(inclLine)
    print DXLVER "\n"
}
else
    print "user file, " userFile " does not exist\n"

 


Right now the user file that I am testing with contains only
DXLVER = "qual"

When I run the above code in the interactive DXL window, the word init, which is the initial setting for DXLVER, is printed instead of qual. I do know that the included file is being included because in my testing I put a print statement in the include file, and it was executed.

Am I doing something wrong or does the eval_ statement not work the way I am thinking? Is there some way to have an include statement with a variable for the filename? (Which is ultimately what I am trying to do.) Also, is the eval_ function documented in the DXL reference manual? I was unable to find it.

We currently are running 8.1.

Thanks,
Marjorie

 


mtmccor - Thu Apr 01 12:29:06 EDT 2010

Re: How to include a user-specific file
Mathias Mamsch - Thu Apr 01 15:42:00 EDT 2010

As you already found out you eval_ runs in its own dxl context, no variables are carried across from and to the calling dxl script. BUT: You can use the undocumented return_ statement to get variables out of eval_ and set the values in the source code to pass parameters:
 

int input = 5
 
   string code = "int par = " input "\n#include <myfile.dxl>; return_ DXLVAR"
 
   string result = eval_ code
   print result

 


I hope you get the idea.

Regards, Mathias

 

Re: How to include a user-specific file
mtmccor - Fri Apr 02 08:27:25 EDT 2010

Mathias answered the question that eval_ runs in its own dxl context, so I can't use it like I was wanting to :(. Does anyone know of a way to include a file with a variable for the directory name?

Thanks

Re: How to include a user-specific file
Mathias Mamsch - Fri Apr 02 13:48:07 EDT 2010

mtmccor - Fri Apr 02 08:27:25 EDT 2010
Mathias answered the question that eval_ runs in its own dxl context, so I can't use it like I was wanting to :(. Does anyone know of a way to include a file with a variable for the directory name?

Thanks

If you look more closely at the example I posted you can see it demonstrated how to pass variables to and get them from to a DXL script running from eval. Adapting it to your code it would be:
 

string curUser = doorsname
string userFile = "C:/Users/" curUser "/settings.dxl"
string DXLVER = "init"
 
if (fileExists_(userFile))
{
    // use return_ after the include statement to get DXLVER out of the context
    string inclLine = "#include \"" userFile "\"\nreturn_ DXLVER"
    // eval_ returns the string that was passed to return_ ...
    DXLVER = eval_(inclLine)
    print DXLVER "\n"
}
else
    print "user file, " userFile " does not exist\n"

 


Regards, Mathias

 

Re: How to include a user-specific file
SystemAdmin - Fri Apr 02 14:40:27 EDT 2010

mtmccor - Fri Apr 02 08:27:25 EDT 2010
Mathias answered the question that eval_ runs in its own dxl context, so I can't use it like I was wanting to :(. Does anyone know of a way to include a file with a variable for the directory name?

Thanks

I hate to state the obvious, but why don't you just open the file, read each line, regex the keys and values out into a Skip list, and use values right out of the list?

Re: How to include a user-specific file
mtmccor - Mon Apr 05 06:43:48 EDT 2010

Mathias Mamsch - Fri Apr 02 13:48:07 EDT 2010

If you look more closely at the example I posted you can see it demonstrated how to pass variables to and get them from to a DXL script running from eval. Adapting it to your code it would be:
 

string curUser = doorsname
string userFile = "C:/Users/" curUser "/settings.dxl"
string DXLVER = "init"
 
if (fileExists_(userFile))
{
    // use return_ after the include statement to get DXLVER out of the context
    string inclLine = "#include \"" userFile "\"\nreturn_ DXLVER"
    // eval_ returns the string that was passed to return_ ...
    DXLVER = eval_(inclLine)
    print DXLVER "\n"
}
else
    print "user file, " userFile " does not exist\n"

 


Regards, Mathias

 

I did understand what you were saying, and I implemented something like what you suggested, but I was hoping for something a little more flexible.

Thanks!
Marjorie

Re: How to include a user-specific file
mtmccor - Mon Apr 05 06:49:16 EDT 2010

SystemAdmin - Fri Apr 02 14:40:27 EDT 2010
I hate to state the obvious, but why don't you just open the file, read each line, regex the keys and values out into a Skip list, and use values right out of the list?

My example was more simplistic than what my overall goal is. I was trying to leave open the possibility that the file being included could have more than just variable settings, in which case your suggestion would not quite work. Based on the responses that I am getting on this inquiry, I think I will have to simplify my goal.

Thanks,
Marjorie

Re: How to include a user-specific file
mtmccor - Mon Apr 12 11:45:34 EDT 2010

Mathias Mamsch - Fri Apr 02 13:48:07 EDT 2010

If you look more closely at the example I posted you can see it demonstrated how to pass variables to and get them from to a DXL script running from eval. Adapting it to your code it would be:
 

string curUser = doorsname
string userFile = "C:/Users/" curUser "/settings.dxl"
string DXLVER = "init"
 
if (fileExists_(userFile))
{
    // use return_ after the include statement to get DXLVER out of the context
    string inclLine = "#include \"" userFile "\"\nreturn_ DXLVER"
    // eval_ returns the string that was passed to return_ ...
    DXLVER = eval_(inclLine)
    print DXLVER "\n"
}
else
    print "user file, " userFile " does not exist\n"

 


Regards, Mathias

 

FYI. I did implement what you suggested with the DXLVER = eval_(inclLine), but the eval of the include file was extremely slow. I have used eval in other cases, and I have not had any performance issues with it, so there must something with how DOORS handles includes that slows it down in this case. I made the file being included simplistic - just setting a variable - to see if complexity of the included file made a difference, but it did not seem to.

Thanks again for the feedback.

Re: How to include a user-specific file
Mathias Mamsch - Mon Apr 12 12:02:27 EDT 2010

mtmccor - Mon Apr 12 11:45:34 EDT 2010
FYI. I did implement what you suggested with the DXLVER = eval_(inclLine), but the eval of the include file was extremely slow. I have used eval in other cases, and I have not had any performance issues with it, so there must something with how DOORS handles includes that slows it down in this case. I made the file being included simplistic - just setting a variable - to see if complexity of the included file made a difference, but it did not seem to.

Thanks again for the feedback.

If your include path is on the network it might be that including a file from there is pretty slow. Or maybe your include environment contains a lot of directories? I don't think that including over eval_ should be any different from including directly. Regards, Mathias

Re: How to include a user-specific file
mtmccor - Mon Apr 12 13:01:09 EDT 2010

Mathias Mamsch - Mon Apr 12 12:02:27 EDT 2010
If your include path is on the network it might be that including a file from there is pretty slow. Or maybe your include environment contains a lot of directories? I don't think that including over eval_ should be any different from including directly. Regards, Mathias

The include path is on the network and the environment contains a lot of directories, but what I did that led me to believe the eval of an include is slow is
- I ran the code with the eval include, which was painfully slow.
- Then I hard-coded in the #include statement in place of the eval include and ran it. That ran quickly.
The paths were the same for both include statements, and the file being included was the same. The only difference is one include was being done with the eval command, and the other was being done directly.

I admit that because of time issues, I didn't play around with it too much more after having it run so slowly, so if I have the time, I will play with it some more.

Thanks!

Re: How to include a user-specific file
Mathias Mamsch - Mon Apr 12 15:00:07 EDT 2010

mtmccor - Mon Apr 12 13:01:09 EDT 2010
The include path is on the network and the environment contains a lot of directories, but what I did that led me to believe the eval of an include is slow is
- I ran the code with the eval include, which was painfully slow.
- Then I hard-coded in the #include statement in place of the eval include and ran it. That ran quickly.
The paths were the same for both include statements, and the file being included was the same. The only difference is one include was being done with the eval command, and the other was being done directly.

I admit that because of time issues, I didn't play around with it too much more after having it run so slowly, so if I have the time, I will play with it some more.

Thanks!

#include tells the DXL parser to just fill in the file (just like in C). If you hardcode the include statement the DXL parser will fill in the DXL file into the source before even starting the DXL. So it will be very fast, since at runtime there will be no more parsing. If you put it into eval_ then the DXL parser will fetch the include file when you start eval_ filling in the contents of the file and then starting execution. If you run the same statement over and over again then it will fetch the time over and over again from the network, since one eval_ does not remember where the last eval_ found the file.

Regards, Mathias